home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWViews / FWEdView.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  7.0 KB  |  210 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWEdView.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWEDVIEW_H
  11. #define FWEDVIEW_H
  12.  
  13. //----------------------------------------------------------------------------------------
  14. // Imported Classes
  15. //----------------------------------------------------------------------------------------
  16.  
  17. #ifndef FWFONT_H
  18. #include "FWFont.h"
  19. #endif
  20.  
  21. #ifndef FWVIEW_H
  22. #include "FWView.h"
  23. #endif
  24.  
  25. #ifndef FWNOTIFR_H
  26. #include "FWNotifr.h"
  27. #endif
  28.  
  29. #if defined(FW_BUILD_MAC) && !defined(__TEXTEDIT__)
  30. #include "TextEdit.h"
  31. #endif
  32.  
  33. //========================================================================================
  34. //    Forward Declaration
  35. //========================================================================================
  36.  
  37. class FW_CString;
  38. class FW_CSuperView;
  39. class FW_CFont;
  40.  
  41.  
  42. //========================================================================================
  43. // class FW_CEditView
  44. //========================================================================================
  45. // FW_CEditView is a wrapper for Macintosh TextEdit, see Inside Macintosh: Text
  46.  
  47. class FW_CEditView: public FW_CView, public FW_MNotifier
  48. {
  49. public:
  50.     FW_DECLARE_CLASS
  51.     FW_DECLARE_AUTO(FW_CEditView)
  52.  
  53.     // EditView attributes
  54.     enum AttrEnum
  55.     {
  56.         kDrawBox         = 0x01,        // draw a 1 pixel frame
  57.         kReadOnly        = 0x02,        // not implemented yet
  58.         kWordWrap        = 0x04,        // wrap long lines
  59.         kAutoScroll        = 0x08,        // scroll when text is out of view
  60.         kOutlineHilite    = 0x10,        // show selection in inactive text edit
  61.         kTextBuffering    = 0x20,        // for 2-byte scripts
  62.         kInlineInput    = 0x40,        // use keyboard input method
  63.         kTextServices    = 0x80        // see Inside Macintosh: Text
  64.     };
  65.                     
  66.     FW_CEditView (Environment* ev, 
  67.                     FW_CSuperView* container, 
  68.                     const FW_CRect& bounds,
  69.                     ODID  viewID,
  70.                     const FW_CString& text, 
  71.                     const FW_CFont& font = FW_kNormalFont,
  72.                     short maxChars = FW_MAXINT16, 
  73.                     unsigned short attributes = FW_CEditView::kDrawBox + 
  74.                                                 FW_CEditView::kWordWrap + 
  75.                                                 FW_CEditView::kAutoScroll);
  76.  
  77.     FW_CEditView (Environment* ev, 
  78.                     FW_CSuperView* container, 
  79.                     const FW_CRect& bounds,
  80.                     ODID  viewID);
  81.                     
  82.     FW_CEditView(Environment* ev);
  83.  
  84.     virtual ~FW_CEditView ();
  85.     
  86.     // ---- Getters
  87.     FW_Boolean                     HasBox() const;
  88.     FW_Boolean                     HasWordWrap() const;
  89.     FW_Boolean                     HasAutoScroll() const;
  90.     unsigned short                GetEditAttributes() const;
  91.     FW_ByteCount                GetMaxChars(Environment* ev) const;
  92.  
  93.     FW_CString                     GetText (Environment* ev) const;
  94.     FW_ByteCount                 GetTextLength (Environment * ev) const;
  95.  
  96.     FW_PlatformHandle            GetPlatformEditHandle(Environment* ev) const;
  97.  
  98.     void                        GetLocale(Environment* ev, FW_Locale& locale) const;
  99.             
  100.     // ---- Text Events
  101.     virtual void                DoTECommand (Environment* ev, ODCommandID id, FW_Boolean useScrap);
  102.     virtual FW_Handled            InputCharKey (Environment* ev, char c);
  103.  
  104.     // ---- Text changes
  105.     virtual void                 SetText (Environment* ev, const FW_CString& text);
  106.     virtual void                 ClearText (Environment* ev);
  107.     virtual void                 InsertText(Environment* ev, const FW_CString& textToInsert, short offset);
  108.     void                         SetFont (Environment* ev, const FW_CFont& font);
  109.     FW_CFont                    GetFont(Environment * ev) const;
  110.  
  111.     // ---- Text Selection
  112.     FW_CString                     GetSelectedText(Environment* ev) const;
  113.     void                         GetSelectionRange(Environment* ev, short& startOffset, short& endOffset) const;
  114.     void                         SetSelectedText(Environment* ev, const FW_CString& newText);
  115.     void                         SelectText (Environment* ev, short startOffset, short endOffset);
  116.     void                         SelectAll (Environment* ev);
  117.     
  118.     // ---- FW_MEventHandler
  119.     virtual FW_Handled             DoIdle (Environment* ev, const FW_CNullEvent& event);
  120.     virtual FW_Handled             DoMouseDown (Environment* ev, const FW_CMouseEvent& event);
  121.     virtual FW_Handled             DoVirtualKey (Environment* ev, const FW_CVirtualKeyEvent & event);
  122.     virtual FW_Handled             DoCharKey (Environment* ev, const FW_CCharKeyEvent& event);
  123.     virtual FW_Handled             DoAdjustMenus (Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot);
  124.     virtual FW_Handled             DoMenu     (Environment* ev, const FW_CMenuEvent& event);
  125.     virtual void                 ActivateTarget (Environment* ev, FW_Boolean tabSelection);
  126.     virtual void                 DeactivateTarget (Environment* ev);
  127.     virtual FW_Boolean             WantsToBeTarget (Environment* ev);
  128.     virtual void                 SetVisible(Environment* ev, FW_Boolean visible, FW_Boolean propagate);
  129.     
  130.     // ---- FW_CView
  131.     virtual FW_Handled             AdjustCursor (Environment* ev, ODFacet* odFacet, const FW_CPoint& where, ODEventInfo* eventInfo);
  132.     virtual void                 Draw (Environment* ev, ODFacet* facet, ODShape* invalidShape);
  133.     virtual void                LocationChanged (Environment* ev, const FW_CPoint& oldLocation);
  134.     virtual void                SizeChanged (Environment* ev, const FW_CPoint& oldSize);
  135.  
  136.     // ----- Archiving -----
  137.     virtual void                Flatten(Environment* ev, FW_CWritableStream& stream) const;
  138.     virtual void                InitializeFromStream(Environment* ev, FW_CReadableStream& stream);
  139.     static void*                Create(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  140.     static void                    Destroy(void* object, FW_ClassTypeConstant type);
  141.     
  142. protected: 
  143.     void                         PrivSelectAll ();
  144.     void                        PrivEnableEditMenu(Environment *ev, FW_Boolean enable);
  145.  
  146.     // ---- Utilities
  147.     void                         Initialize(Environment* ev, const FW_CString& str, const FW_CFont& font);
  148.     FW_CRect                     GetTextBounds (Environment* ev);
  149.     void                         MacAdjustRects (Environment* ev, FW_CGraphicContext & gc);
  150.     void                         MacSetRects (Environment* ev);
  151.     inline TEHandle             MacTE() const { return fMacTEHandle; }
  152.     FW_Boolean                  PrivCheckMaxChars(long numChars);
  153.     
  154. private:
  155.     TEHandle                    fMacTEHandle;
  156.     short                        fMaxChars;
  157.     unsigned short                fEditAttributes;
  158. };
  159.  
  160.  
  161. //========================================================================================
  162. //     Inlines
  163. //========================================================================================
  164.  
  165. inline    FW_PlatformHandle    FW_CEditView::GetPlatformEditHandle(Environment*) const
  166. {
  167. #ifdef FW_BUILD_MAC
  168.     return (FW_PlatformHandle)fMacTEHandle;
  169. #endif
  170. }
  171.  
  172. inline    FW_ByteCount    FW_CEditView::GetMaxChars(Environment*) const
  173. {
  174. #ifdef FW_BUILD_MAC
  175.     return (FW_ByteCount)fMaxChars;
  176. #endif
  177. }
  178.  
  179. //---------------------------------------------------------------------------------------------------
  180. //     attributes
  181. //---------------------------------------------------------------------------------------------------
  182.  
  183. inline FW_Boolean FW_CEditView::HasBox() const
  184. {
  185.     return fEditAttributes & FW_CEditView::kDrawBox;
  186. }
  187.  
  188. inline FW_Boolean FW_CEditView::HasWordWrap() const
  189. {
  190.     return fEditAttributes & FW_CEditView::kWordWrap;
  191. }
  192.  
  193. inline FW_Boolean FW_CEditView::HasAutoScroll() const
  194. {
  195.     return fEditAttributes & FW_CEditView::kAutoScroll;
  196. }
  197.  
  198. inline unsigned short FW_CEditView::GetEditAttributes() const
  199. {
  200.     return fEditAttributes;
  201. }
  202.  
  203. inline void FW_CEditView::SelectAll (Environment* ev)
  204. {
  205.     SelectText(ev, 0, FW_MAXINT16);
  206. }
  207.  
  208. #endif // FWEDVIEW_H
  209.  
  210.